﻿using MediatR;
using ProcurementManagement.Applcation.Command.QualityCommand;
using ProcurementManagement.Infrstructre.Interface;

namespace ProcurementManagement.Applcation.CommandHanlers.QualityCommandHandler
{
    public class DelProApplyCommandHandlers : IRequestHandler<DelProApplyCommand, int>
    {

        private readonly IProPcApplyRepository applyRepository;

        public DelProApplyCommandHandlers(IProPcApplyRepository applyRepository)
        {
            this.applyRepository = applyRepository;
        }


        public async Task<int> Handle(DelProApplyCommand request, CancellationToken cancellationToken)
        {
            var list = (await applyRepository.GetAll()).Where(x=>request.ids.Contains(x.ProApplyId)).ToList();
            foreach (var item in list)
            {
                item.IsDel = true;
                await applyRepository.UpdataAsync(item);
            }
            return 1;
        }
    }
}
